package com.learn._02notice.base.response;

import jdk.net.SocketFlow;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    private Integer state;
    private String message;
    private Object data;

    /*
    * 针对没有具体数据返回的状态码
    * */
   /* public JsonResult(Integer state, String message) {
        this.state = state;
        this.message = message;
    }*/
    public JsonResult(StatusCode statusCode){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    /*
    * 针对有具体数据返回的状态码
    * */
    public JsonResult(StatusCode statusCode,Object data){
        this.state=statusCode.getState();
        this.message=statusCode.getMessage();
        this.data=data;
    }

    /*
    * 封装2个静态方法：只针对操作成功的场景：
    *  针对有具体数据返回的控制器方法
    *  针对没有具体数据返回的控制器方法
    * */
    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }

    public static JsonResult ok(){
        return ok(null);
    }

}
